
function insertOrderIsStatusPending(url)
{
	var bool = false;
	 $.ajax({
	        type: "GET",
	        url: url + "/cart/insertOrderIsStatusPending",
	        error: 
	         function(ts){
	        	if(ts.responseText != 'false'){
	        		bool = true;
	        	}
	         },
	        success:
	        	function(result){
	        		bool = true;
	        	}	
	        }
	 );	 
	 return bool;	      
}



function add_to_cart(product_id,url){
	// alert("id: " + product_id + " url: " +url)
	// $('#alert').html('success');
	
	$.post(url + "/cart/add_cart_item", { id: product_id, quantity: 1 },
			function(data){
				if(data == 'true'){
					alert('thêm sản phẩm thành công');
				}else{
					alert('thêm sản phẩm thất bại');
				}
		}		
	);
}

function update_to_cart(id,rid,link,price){
	
	
	 var qty = $('#quantity_' + id).val(); 
	 
	 
	 $.ajax({
	        type: "GET",
	        url: link + "/cart/update_cart_item",
	        dataType:"json",
	        data: "rid="+rid+"&qty="+qty+"&price="+price,

	        error: 
	         function(ts){
	        	alert(ts.responseText);
	          if(ts.responseText.message != 'false')
	          {
	        	  
	           if(qty < 1){
	               $('#row_' + id).remove();
	              }else{
	            	  /* var money = qty * ($('#price_' + id).html()); */
	            	/* var money1 = number_format(money); */
	            	  /* $.formatNumber(money,{format:"#,###.00",locate:"us"}) */
	            	  /* alert(money); */
	               $('#total_price_' + id).html(ts.responseText.sub);  
	            	  
	              }
	           $('#total_cost').html(ts.responseText.cost);
	           
	          }else{
	           alert('update that bai');
	          }
	         },
	     success: 
	         function(result){
	                if(result.message != 'false'){
	                 if(qty < 1){
	                  $('#row_' + id).remove();
	                 }
	                 else{
	                  $('#total_price_' + id).html( result.sub);  
	                 }
	                 
	                 $('#total_cost').html(result.cost);
	                }else{
	                 alert('update that bai');
	                }
	              } ,
	 });

	      return false;
	      
	    
	}

function remove_to_cart(id,rid,link){
	
	$.ajax({
        type: "GET",
        url: link + "/cart/remove_cart_item",
        data: "rowid="+rid+"&quantity=0",
        cache:false,
        error: 
          function(ts){
        	
            if(ts.responseText != 'false'){
        		$('#row_' + id).remove();
            	$('#total_cost').html(ts.responseText);
            }
          },
          success: 
 	         function(result){
 	                if(result != 'false'){
 	                 if(qty < 1){
 	                  $('#row_' + id).remove();
 	                 }
 	                 else{
 	                  $('#total_price_' + id).html( qty * $('#price_' + id).html());  
 	                 }
 	                 
 	                 $('#total_cost').html(result);
 	                }else{
 	                 alert('update that bai');
 	                }
 	              } ,
        
        });

      return false;
    
}